package com.ruoyi.dance.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dance.domain.vo.DancePageVo;
import com.ruoyi.dance.domain.bo.DancePageBo;
import com.ruoyi.dance.service.IDancePageService;

/**
 * 页面管理
 *
 * @author ruoyi
 * @date 2024-01-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Dance/page")
public class DancePageController extends BaseController {

    private final IDancePageService iDancePageService;

    /**
     * 查询页面管理列表
     */
    @SaCheckPermission("Dance:page:list")
    @GetMapping("/list")
    public R<List<DancePageVo>> list(DancePageBo bo) {
        List<DancePageVo> list = iDancePageService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出页面管理列表
     */
    @SaCheckPermission("Dance:page:export")
    @Log(title = "页面管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DancePageBo bo, HttpServletResponse response) {
        List<DancePageVo> list = iDancePageService.queryList(bo);
        ExcelUtil.exportExcel(list, "页面管理", DancePageVo.class, response);
    }

    /**
     * 获取页面管理详细信息
     *
     * @param pageId 主键
     */
    @SaCheckPermission("Dance:page:query")
    @GetMapping("/{pageId}")
    public R<DancePageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long pageId) {
        return R.ok(iDancePageService.queryById(pageId));
    }

    /**
     * 新增页面管理
     */
    @SaCheckPermission("Dance:page:add")
    @Log(title = "页面管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DancePageBo bo) {
        return toAjax(iDancePageService.insertByBo(bo));
    }

    /**
     * 修改页面管理
     */
    @SaCheckPermission("Dance:page:edit")
    @Log(title = "页面管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DancePageBo bo) {
        return toAjax(iDancePageService.updateByBo(bo));
    }

    /**
     * 删除页面管理
     *
     * @param pageIds 主键串
     */
    @SaCheckPermission("Dance:page:remove")
    @Log(title = "页面管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pageIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] pageIds) {
        return toAjax(iDancePageService.deleteWithValidByIds(Arrays.asList(pageIds), true));
    }
}
